/**
 * 
 */
package com.thon.dao.util;


import java.util.Date;
import java.util.List;

import com.thon.dao.util.AbstractDao;
import com.thon.dao.util.Page;
import com.thon.entity.util.IdEntity;

public abstract class AbstractDatabaseAnalysis<E extends IdEntity> extends AbstractDao<E> implements DataAnalysisDao<E>{
	

	protected Class<E> entityClass;

	public AbstractDatabaseAnalysis(Class<E> entityClass) {
		super(entityClass);		
		this.entityClass = entityClass;
	}

	public List<E> getDataList(Date startDate, Date endDate) 	{		
		
		String querySql = "FROM "+entityClass.getSimpleName()+" d where d.creatDate >= ? and d.creatDate <= ? order by d.creatDate desc,d.type.id desc";
		return findList(querySql,null,startDate,endDate);
	
	}
	
	public List<E> getDataList(Date startDate, Date endDate,String ids) 	{		
		
		String querySql = "FROM "+entityClass.getSimpleName()+" d where d.creatDate >= ? and d.creatDate <= ? and d.type.id in ("+ids+") order by d.creatDate desc,d.type.id desc";
		return findList(querySql,null,startDate,endDate);
	
	}

	public Page<E> getDataPage(Page<E> page,Date startDate, Date endDate,String ids) {		
		String querySql = "FROM "+entityClass.getSimpleName()+" d where d.creatDate >= ? and d.creatDate<= ? and d.type.id in ("+ids+") order by d.creatDate desc,d.type.id desc";
		return findPage(page,querySql,startDate,endDate);	
	}
	
	public List<E> getDataTypeSum(Date startDate, Date endDate,String ids) 	{		
		
		String querySql = "SELECT SUM(d.value) FROM E d where d.creatDate >= ? and d.creatDate < ? and d.type.id in ("+ids+") order by d.creatDate desc,d.type.id desc";
		return findList(querySql,null,startDate,endDate);
	
	}

	
}
